package cn.ante.basic.service.impl;

import cn.ante.basic.mapper.BaseMapper;
import cn.ante.basic.query.BaseQuery;
import cn.ante.basic.service.IBaseService;
import cn.ante.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    /*
    * @Title: loadAll
    * @Description: 根据高级查询的得到的集合
    * @Author: Nai
    * @Version: 1.0
    * @Date:  2022/6/21 18:57
    * @Parameters: [departmentQuery]
    * @Return cn.ante.basic.utils.PageList<cn.ante.org.domain.Department>
    */


    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    @Override
    @Transactional
    public void add(T t) {
        baseMapper.add(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        baseMapper.remove(id);
    }

    @Override
    @Transactional
    public void batchDel(Long[] ids) {
        baseMapper.batchDel(ids);
    }

    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    @Override
    public PageList<T> findAll(BaseQuery baseQuery) {
        Integer total = baseMapper.pageCount(baseQuery);
        List<T> rows = baseMapper.findAll(baseQuery);
        return new PageList<T>(total,rows);
    }
}
